<?php require_once "config/config.php"; ?>

<!-- ----------------------------------------------------------------------- -->

<nav class="navbar navbar-dark bg-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="<?php echo $homepage; ?>" target="_self">Todo</a>
        <button id="btnNavbarToggler" class="navbar-toggler" type="button">
            <span class="navbar-toggler-icon"></span>
        </button>
    </div>
</nav>
<div class="collapse" id="navbarToggleExternalContent">
    <div class="bg-secondary p-4">
        <p class="text-white">
            <a id="signout" href="#" class="text-white text-decoration-none" target="_self">注销登录</a>
        </p>
    </div>
</div>

<!-- ----------------------------------------------------------------------- -->

<script src="resources/bootstrap-5.2.0-beta1-dist/js/bootstrap.min.js"></script>
<script src="resources/jQuery/jquery-3.5.1.js"></script>

<!-- ----------------------------------------------------------------------- -->

<script>

    // 添加 cookie
    function setCookie(name,value,days) {
        var expires = "";
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days*24*60*60*1000));
            expires = "; expires=" + date.toUTCString();
        }
        document.cookie = name + "=" + (value || "")  + expires + "; path=/";
    }

    // 查询 cookie
    function getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }

    // 删除 cookie
    function eraseCookie(name) {
        document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    }
</script>

<!-- ----------------------------------------------------------------------- -->

<script>
    $("#signout").click(function () {
        eraseCookie('<?php echo $cookieUsername; ?>');
        eraseCookie('<?php echo $cookiePassword; ?>');
        location.reload();
    });
</script>

<!-- ----------------------------------------------------------------------- -->

<script>
    $("#btnNavbarToggler").click(function () {
        if ($("#navbarToggleExternalContent").is(":hidden")) {
            $("#navbarToggleExternalContent").slideDown()
        } else {
            $("#navbarToggleExternalContent").slideUp()
        }
    })
</script>

<!-- ----------------------------------------------------------------------- -->
